package com.cloud.edu.sys.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloud.edu.sys.dao.SqlAdapterMapper;
import com.cloud.edu.sys.dao.UserMapper;
import com.cloud.edu.sys.model.User;
import com.cloud.edu.sys.model.UserExample;
import com.cloud.edu.sys.service.SysUserService;
import com.cloud.edu.utils.PageUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

/**
 * 系统用户
 * 
 * @author dehuisun
 * @date 2018-11-25
 */
@Service("sysUserService")
public class SysUserServiceImpl implements SysUserService{

	@Autowired
	private UserMapper userMapper;
	
	@Autowired
   	private SqlAdapterMapper sqlAdapterMapper;//注入dao
	
	/**
	 * 分页数据
	 */
	@Override
	public PageUtils queryPage(Map<String, Object> params) {
		PageUtils pageUtils=PageUtils.getPageInfo(params);
		Page<Object> p = PageHelper.startPage(pageUtils.getPage(), pageUtils.getLimit());
		StringBuffer sql=new StringBuffer(" select * from sys_user");
		sqlAdapterMapper.selectSQL(sql.toString());
		pageUtils =new PageUtils(p);
		return pageUtils;
	}

	@Override
	public List<String> queryAllPerms(Long userId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<String> queryAllMenuId(Long userId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public User queryByUserName(String username) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void save(User user) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void update(User user) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void deleteBatch(Long[] userIds) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean updatePassword(Long userId, String password,
			String newPassword) {
		// TODO Auto-generated method stub
		return false;
	}
	
	/**
	 * 根据User获取数据
	 * @param User
	 * @return List<User>
	 */
	@Override
	public List<User> getUser(User user) throws Exception{
		// TODO Auto-generated method stub
		UserExample example = new UserExample();
		com.cloud.edu.sys.model.UserExample.Criteria criteria= example.createCriteria();
		if(user.getUsername() != null && !user.getUsername().equals("")){
			criteria.andUsernameEqualTo(user.getUsername());
		}
		List<User> list = userMapper.selectByExample(example);
		return list;
	}

	
}
